classdef test_lqr_policy < experiment
    
    properties
    end
    
    methods
        %  test_lqr_policy().run_test
        function test(obj,training_policy,training_duration,lqr_duration) 
            warning('off', 'MATLAB:hg:JavaSetHGPropertyParamValue')
            system=system_base();
            policy = test_mpc2_kalman_integral_queue_linearized(system); 
            workload = system.initialize(training_duration+lqr_duration);
            % im not training anymore 
            % system.run_plan(system, training_duration,  training_policy);
            % model=linear_model();
            policy.build_model( system.past_inst(), system.past_util());
            % prediction = mpc_policy.predict_choice_outcome(choice,  system.past_future_inst(), system.past_util(), system.t-1 );
            system.run_plan(system, lqr_duration , policy);    
                       
            tot_fired_inst  = sum(system.fired_inst,1);
            disp(strcat('tot_fired_inst:',num2str(tot_fired_inst)));
            tot_cost=system.inst_cost(tot_fired_inst );
            disp(strcat('tot_cost:',num2str(tot_cost)));
            disp('system.fired_inst are ...');
            for i=1:size(system.fired_t,1)
                disp(strcat(num2str(system.fired_t(i)),'-->', num2str(system.fired_inst(i,:))));
            end
            figure
            subplot(2,1,1); plot(system.past_util());
            subplot(2,1,2); plot( system.past_future_inst()  );
            rt_vec=system.past_util();  inst_count_vec=system.past_future_inst();
            % save('data/experiment-fullloop_day42_t20_caw20_weightdot5.mat', 'inst_count_vec', 'rt_vec');
        end
     
        % > test_lqr_policy().run_test
        function run_test(obj)
            p1=  static_policy(@()...
                [1, 1, 2, 1 %fire 1 instance of type 1 at min 1
                5,  1, 1, 0
                14,1, 1, 1
                28,1, 2, 1
                34,1, 2, 1]);
            
            p0=static_policy(@()...
                [1,  1, 3, 1  % fire 3 instances of type 1 at min 1
                4,  2, 2, 1
                5,  1, 2, 0
                9,  3, 7, 1
                12, 2, 2, 0
                14, 4, 4, 1
                17, 3, 5, 0
                18, 5, 1, 1
                21, 4, 4, 0
                24, 6, 5, 1
                28, 5, 1, 0
                30, 7, 1, 1
                35, 6, 5, 0
                35, 8, 2, 1
                37, 7, 1, 0
                41, 9, 1, 1
                45, 8, 2, 0
                49,10, 2, 1
                50, 9, 1,  0
                54,11, 1, 1]);
            
            p2=static_policy(@()[1,   3,  2, 1]);
            choice=[0 0 2 0 0 0 0 0 0 0 0 ];
            obj.test(p0,0,4*60); % 4*60
        end
        
    end
    
end

